package com.cdty.chess.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/api/v1/api/live")
public class LiveController {

    @Value("${srs.webrtc.url}")  // 在application.properties中配置
    private String srsWebrtcUrl;

    @PostMapping("/create")
    public ResponseEntity<Map<String, String>> createStream() {
        String streamKey = UUID.randomUUID().toString();
        Map<String, String> response = new HashMap<>();
        response.put("webrtc_push_url", "webrtc://" + srsWebrtcUrl + "/live/" + streamKey);
        response.put("flv_play_url", "http://" + srsWebrtcUrl + ":8080/live/" + streamKey + ".flv");
        return ResponseEntity.ok(response);
    }
}